package island.gotenyama.wand.exception;

import island.gotenyama.wand.bean.Conveyancable;
import island.gotenyama.wand.bean.Conveyance;
import island.gotenyama.wand.bean.MessageKey;

import org.springframework.util.Assert;

/**
 * 論理例外を表すクラス<br>
 * 
 * @author tk
 */
public class LogicalException extends Exception implements Conveyancable {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * NO Conveyance Message
	 */
	protected static final String ERROR_MSG = "No Conveyance";

	/**
	 * デフォルト値
	 */
	protected static final MessageKey defMessageKey = new MessageKey("logicalError");

	/**
	 * Conveyance
	 */
	private final Conveyance conveyance;

	/**
	 * Constractor
	 * 
	 * @param errMsg Error Message
	 */
	public LogicalException(String errMsg) {
		this.conveyance = new Conveyance(defMessageKey, errMsg);
	}
	
	/**
	 * Constractor
	 * 
	 * @param errMsg Error Message
	 * @param e UpException
	 */
	public LogicalException(String errMsg, final Exception e) {
		super(e);
		this.conveyance = new Conveyance(defMessageKey, errMsg);
	}
	
	/**
	 * Constractor
	 * 
	 * @param conveyance Conveyance
	 */
	public LogicalException(final Conveyance conveyance) {
		Assert.notNull(conveyance, ERROR_MSG);
		this.conveyance = conveyance;
	}

	/**
	 * Constractor
	 * 
	 * @param conveyance Conveyance
	 * @param e UpException
	 */
	public LogicalException(final Conveyance conveyance, final Exception e) {
		super(e);
		Assert.notNull(conveyance, ERROR_MSG);
		this.conveyance = conveyance;
	}

	/**
	 * Get Conveyance
	 * 
	 * @return Conveyance
	 */
	public Conveyance getConveyance() {
		return conveyance;
	}
}
